﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NaiveBayesClassifier
{
    class CBaseConcept : IConcept
    {
        private string name;
        private CBaseConcept parent;
        private List<IInstance> instances = new List<IInstance>();

        public CBaseConcept(string name)
        {
            this.name = name;
        }

        public CBaseConcept(string name, CBaseConcept parent)
        {
            this.name = name;
            this.parent = parent;
        }

        public void AddInstance(IInstance instance)
        {
            instances.Add(instance);
        }

        #region Getter and Setter
        public string GetName()
        {
            return name;
        }

        public IConcept GetParent()
        {
            return parent;
        }

        public void SetParent(CBaseConcept parent)
        {
            this.parent = parent;
        }

        public IInstance[] GetInstances()
        {
            return instances.ToArray();
        }
        #endregion

        public override bool Equals(object obj)
        {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (!(obj is CBaseConcept))
                return false;
            CBaseConcept other = (CBaseConcept)obj;
            if (name == null)
            {
                if (other.name != null)
                    return false;
            }
            else if (!name.Equals(other.name))
                return false;
            if (parent == null)
            {
                if (other.parent != null)
                    return false;
            }
            else if (!parent.Equals(other.parent))
                return false;
            return true;
        }

        public override int GetHashCode()
        {
            return name.GetHashCode();
        }
    }
}
